package io.kiki.sba.registry.common.model.store;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.kiki.sba.registry.common.model.ClientInterfaceId;
import io.kiki.sba.registry.common.model.PublishSource;
import io.kiki.sba.registry.common.model.PublishType;
import io.kiki.sba.registry.common.model.ServerData;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Setter
@Getter
public class Publisher extends BaseInfo {

    private static final long serialVersionUID = 1L;

    private List<ServerData> serverDataList;

    private PublishType publishType = PublishType.normal;

    private PublishSource publishSource = PublishSource.client;

    @JsonIgnore
    private ClientInterfaceId clientInterfaceId;

    public Publisher() {
    }


    public static void internPublisher(List<Publisher> publishers) {
        for (Publisher publisher : publishers) {
            internPublisher(publisher);
        }
    }

    /**
     * change publisher word cache
     */
    public static Publisher internPublisher(Publisher publisher) {
        publisher.setRegisterId(publisher.getRegisterId());
        publisher.setDataInfoId(publisher.getDataInfoId());
        publisher.setInstanceId(publisher.getInstanceId());
        publisher.setGroup(publisher.getGroup());
        publisher.setDataId(publisher.getDataId());
        publisher.setClientId(publisher.getClientId());
        publisher.setZone(publisher.getZone());
        publisher.setProcessId(publisher.getProcessId());
        publisher.setAppName(publisher.getAppName());
        publisher.setClientUrl(Url.internURL(publisher.getClientUrl()));
        publisher.setServerUrl(Url.internURL(publisher.getServerUrl()));
        publisher.setAttributes(publisher.getAttributes());
        return publisher;
    }


    @Override
    @JsonIgnore
    public DataType getDataType() {
        return DataType.publisher;
    }

}
